<template>
	<view class="login acea-row row-column row-middle">
		<view class="logo">
			<image src="../../static/images/Group.png" mode=""></image>
		</view>
		<image class="title" src="../../static/images/login-title.png"/>
		<button class="btn acea-row row-middle row-center" v-if="isWxwork" @click="wxlogin">
			<u-icon name="weixin-fill" color="#ffffff" size="48" style="margin-right: 12px;"></u-icon> 企业微信登录
		</button>
		<button class="btn acea-row row-middle row-center" v-else open-type="getPhoneNumber" @click="wxlogin" @getphonenumber="getphonenumber">
			<u-icon name="weixin-fill" color="#ffffff" size="48" style="margin-right: 12px;"></u-icon> 微信用户一键登录
		</button>
		<view class="phone" @click="common.go('/pages/pack/login/login-phone')" v-if="!isWxwork">手机号登录</view>
		<login-footer />
	</view>
</template>

<script>
	import common from '../../api/common.js'
	import login from '../../api/login.js'
	import request from '../../api/request.js'
	const app = getApp()
	export default{
		data(){
			return{
				common,
				isWxwork:false, // 是否为企业微信
				code:''
			}
		},
		created() {
			this.isWxwork = app.globalData.isWxwork
			console.log(app.globalData.isWxwork)
		},
		methods:{
			wxlogin(){
				const that = this
				if(this.isWxwork){ //企业微信模式
					wx.qy.login({   
						success(e){
							that.code = e.code
							let data = {
								code:e.code
							}
							request.go((e)=>{
								if(e.code == 200){
									login.login_judge(e.data)
								}
							},'/qywechat/loginm',data,"POST")
						}
					})
				}else{
					uni.login({
						success(e) {
							that.code = e.code
						}
					})
				}
			},
			getphonenumber(res){
				let data = {
					code:this.code,
					encryptedData:res.detail.encryptedData,
					iv:res.detail.iv
				}
				if(!data.encryptedData){
					uni.showToast({
						icon:"none",
						title:"请授权"
					})
					return false;
				}
				request.go((e)=>{
					login.login_judge(e.data)
				},"/Login/xcxlogina",data,'POST')
			},
		}
	}
</script>

<style scoped>
	.login{
		height: 100vh;
		position: relative;
	}
	.logo{
		margin-top: 288rpx;
		width: 160rpx;
		height: 160rpx;
		opacity: 1;
		background: #1661ff;
		border-radius: 48rpx;
	}
	.logo image{
		width: 110rpx;
		height: 94rpx;
		margin: 33rpx 0 0 33rpx;
	}
	.title{
		margin-top: 48rpx;
		width: 176rpx;
		height: 40rpx;
	}
	.btn{
		width: 622rpx;
		height: 96rpx;
		background: #1661ff;
		border-radius: 96rpx;
		margin-top: 188rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		font-size: 30rpx;
	}
	.phone{
		margin-top: 32rpx;
		color: #606266;
		text-align: center;
		font-size: 28rpx;
		line-height: 40rpx;
		font-weight: 400;
		font-family: PingFang SC, PingFang SC-Regular;
	}
</style>
